package com.tidc.seaquartz.job;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.tidc.seaquartz.util.RabbitUtil;
import com.tidc.seaservermapper.dao.RabbitMessageLogDao;
import com.tidc.seaservermodel.config.RabbitConfig;
import com.tidc.seaservermodel.entity.Commitment;
import com.tidc.seaservermodel.entity.RabbitMessageLog;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.scheduling.quartz.QuartzJobBean;

import javax.annotation.Resource;

/**
 * @author ：冯涛滔
 * @date ：Created in 2020/10/6 18:08
 * @description：
 * @modified By：
 * @version:
 */
@Slf4j
public class CheckCommitmentOutJob extends QuartzJobBean {
    @Resource
    private RabbitMessageLogDao rabbitMessageLogDao;
    @Resource
    private RabbitUtil rabbitUtil;
    @Resource
    private ObjectMapper objectMapper;
    @SneakyThrows
    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) {
        JobDetail jobDetail = jobExecutionContext.getJobDetail();
        JobDataMap jobDataMap = jobDetail.getJobDataMap();
        Commitment commitment = (Commitment) jobDataMap.get("commitment");
        RabbitMessageLog rabbitMessageLog = RabbitMessageLog.checkCommitmentOut(objectMapper.writeValueAsString(commitment));
        rabbitMessageLogDao.insert(rabbitMessageLog);
        rabbitUtil.sendMQ(rabbitMessageLog);
        log.info("定时任务: 检查奖励是否被及时兑现 commitment {}",commitment);
    }
}
